define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'category_quan/index' + location.search,
                    add_url: 'category_quan/add',
                    edit_url: 'category_quan/edit',
                    del_url: 'category_quan/del',
                    multi_url: 'category_quan/multi',
                    import_url: 'category_quan/import',
                    table: 'category_quan',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'category_id', title: __('Category_id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'category.name', title: __('Category_id'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'quan_name', title: __('Quan_name'), operate: 'LIKE'},
                        {field: 'quan_face_price', title: __('Quan_face_price'), operate:'BETWEEN'},
                        {field: 'quan_price', title: __('团购价'), operate:'BETWEEN'},
                        {field: 'expire_time', title: __('Expire_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'is_used', title: __('Is_used'), formatter: function (value, row, index) {
                                return value == 1 ? '已使用' : '未使用';
                            }},
                        {field: 'type', title: __('来源'), formatter: function (value, row, index) {
                                return value == 1 ? '美团' : '抖音';
                            }},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'used_time', title: __('Used_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},


                        // {field: 'category.id', title: __('Category.id')},
                        // {field: 'category.pid', title: __('Category.pid')},
                        // {field: 'category.type', title: __('Category.type'), operate: 'LIKE'},
                        // {field: 'category.name', title: __('Category.name'), operate: 'LIKE'},
                        // {field: 'category.nickname', title: __('Category.nickname'), operate: 'LIKE'},
                        // {field: 'category.flag', title: __('Category.flag'), operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        // {field: 'category.image', title: __('Category.image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'category.keywords', title: __('Category.keywords'), operate: 'LIKE'},
                        // {field: 'category.description', title: __('Category.description'), operate: 'LIKE'},
                        // {field: 'category.diyname', title: __('Category.diyname'), operate: 'LIKE'},
                        // {field: 'category.createtime', title: __('Category.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'category.updatetime', title: __('Category.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'category.weigh', title: __('Category.weigh')},
                        // {field: 'category.status', title: __('Category.status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        // {field: 'category.dizhi', title: __('Category.dizhi'), operate: 'LIKE'},
                        // {field: 'category.yingye', title: __('Category.yingye'), operate: 'LIKE'},
                        // {field: 'category.user_id', title: __('Category.user_id')},
                        // {field: 'category.xing', title: __('Category.xing'), operate: 'LIKE'},
                        // {field: 'category.price', title: __('Category.price'), operate:'BETWEEN'},
                        // {field: 'category.juli', title: __('Category.juli'), operate: 'LIKE'},
                        // {field: 'category.lng', title: __('Category.lng'), operate: 'LIKE'},
                        // {field: 'category.lat', title: __('Category.lat'), operate: 'LIKE'},
                        // {field: 'category.phone', title: __('Category.phone'), operate: 'LIKE'},
                        // {field: 'category.jiameng_id', title: __('Category.jiameng_id')},
                        // {field: 'category.business_stare_time', title: __('Category.business_stare_time'), operate: 'LIKE'},
                        // {field: 'category.business_end_time', title: __('Category.business_end_time'), operate: 'LIKE'},
                        // {field: 'category.hall_lock_id', title: __('Category.hall_lock_id'), operate: 'LIKE'},
                        // {field: 'category.lock_client_id', title: __('Category.lock_client_id'), operate: 'LIKE'},
                        // {field: 'category.lock_client_secret', title: __('Category.lock_client_secret'), operate: 'LIKE'},
                        // {field: 'category.lock_username', title: __('Category.lock_username'), operate: 'LIKE'},
                        // {field: 'category.lock_password', title: __('Category.lock_password'), operate: 'LIKE'},
                        // {field: 'category.message_name', title: __('Category.message_name'), operate: 'LIKE'},
                        // {field: 'category.message_secret', title: __('Category.message_secret'), operate: 'LIKE'},
                        // {field: 'category.end_time_min', title: __('Category.end_time_min')},
                        // {field: 'category.end_time_content', title: __('Category.end_time_content'), operate: 'LIKE'},
                        // {field: 'user.id', title: __('User.id')},
                        // {field: 'user.group_id', title: __('User.group_id')},
                        // {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        // {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        // {field: 'user.password', title: __('User.password'), operate: 'LIKE'},
                        // {field: 'user.salt', title: __('User.salt'), operate: 'LIKE'},
                        // {field: 'user.email', title: __('User.email'), operate: 'LIKE'},
                        // {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        // {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'user.level', title: __('User.level')},
                        // {field: 'user.gender', title: __('User.gender')},
                        // {field: 'user.birthday', title: __('User.birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'user.bio', title: __('User.bio'), operate: 'LIKE'},
                        // {field: 'user.money', title: __('User.money'), operate:'BETWEEN'},
                        // {field: 'user.score', title: __('User.score')},
                        // {field: 'user.successions', title: __('User.successions')},
                        // {field: 'user.maxsuccessions', title: __('User.maxsuccessions')},
                        // {field: 'user.prevtime', title: __('User.prevtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.logintime', title: __('User.logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.loginip', title: __('User.loginip'), operate: 'LIKE'},
                        // {field: 'user.loginfailure', title: __('User.loginfailure')},
                        // {field: 'user.joinip', title: __('User.joinip'), operate: 'LIKE'},
                        // {field: 'user.jointime', title: __('User.jointime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.createtime', title: __('User.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.updatetime', title: __('User.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'user.token', title: __('User.token'), operate: 'LIKE'},
                        // {field: 'user.status', title: __('User.status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        // {field: 'user.verification', title: __('User.verification'), operate: 'LIKE'},
                        // {field: 'user.openid', title: __('User.openid'), operate: 'LIKE'},
                        // {field: 'user.session_key', title: __('User.session_key'), operate: 'LIKE'},
                        // {field: 'user.code', title: __('User.code'), operate: 'LIKE'},
                        // {field: 'user.access_token', title: __('User.access_token'), operate: 'LIKE'},
                        // {field: 'user.is_clerk', title: __('User.is_clerk')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
